package utils

import (
	"fmt"
	"io/fs"
	"io/ioutil"
	"os"
)

func LsDir(path string) []fs.FileInfo {
  dirList, err := ioutil.ReadDir(path)
  if err != nil {
    fmt.Println(err)
  }
  return dirList
}

func IsExist(path string) bool {
	_, err := os.Stat(path)
	return !os.IsNotExist(err)
}

// 平铺目录, 广度遍历
func FlatDir(path string) []fs.FileInfo {
  fileInfoList := LsDir(path)
  for _, f := range fileInfoList {
    if f.IsDir() {
      nextLayerList := FlatDir(path + "/" + f.Name())
      fileInfoList = append(fileInfoList, nextLayerList...)
    }
  }
  return fileInfoList
}